import { createWebHistory, createRouter } from 'vue-router'

import HomeView from '../views/home/index.vue'
import Login from '../views/login.vue'
import Detail from '../views/detail.vue'
import Goods from '../views/goods.vue'
import Order from '../views/order.vue'


import Home from '../views/home/home.vue'
import Sort from '../views/home/sort.vue'
import Cart from '../views/home/cart.vue'
import My from '../views/home/my.vue'
const routes = [
    { path: '/', redirect: '/home' },
    {
        path: '/home',
        component: HomeView,
        children: [
            {
                path: '/home',
                component: Home,
            },
            {
                path: '/sort',
                component: Sort,
            },
            {
                path: '/cart',
                component: Cart,
            },
            {
                path: '/my',
                component: My,
            },
        ]
    },
    {
        path: '/login',
        component: Login,
    },
    {
        path: '/detail',
        component: Detail,
    },
    {
        path: '/goods',
        component: Goods,
    },
    {
        path: '/order',
        component: Order,
    },
]

export const router = createRouter({
    history: createWebHistory(),
    routes,
})

// router.beforeEach((to, from, next) => {
//     if(to.path=='/Cart'){
//         const token = localStorage.getItem('tooken','asdfggfd')
//         if(token){
//             next()
//         } else{
//             next('/Login')
//         }
//     } else{
//         next()
//     }
// })